// 引用路由
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

const store = new Vuex.Store({
   state: {
      moduleTransitionName: 'slide', //转场时候的动画，不同组件不同动画
      userSubscribeInfo: { // 从微信跳转过来之后的，带回的信息
         channel: '', // 渠道编号
         openid: '', // 微信openid
         unionid: '', // 微信unionid
         bind: '', // 是否绑定手机号 0未绑定 1已绑定
         subscribe: '', // 是否关注微信公众号 0否 1是
         activityId: '' // 表示在某活动下绑定的微信号 
      },
      activityList: [],
      // 服务器时间
      serverTime: '',
      //当前城市的id和名称
      currentCityInfo: {
         cityName: '',
         fullName: '',
         cityCode: '',
         startTime: ''
      },
      // 当前活动信息
      currentActivityInfo: {},
      // 是否新老用户
      isNew: '',
      // 获奖信息
      ownPrizeInfo: {},
      isShowCity: !1,
      isShowRule: !1,
      isSignSuccess: !1,
      isShowQR: !1,
      isShowAtbi: !1,
      isShowQuan: !1,
      isShowBind: !1,
      isShowNoHurry: !1,
      isShowSignShareAttentionYes: !1,
      isShowSignShareAttentionNo: !1,
      isShowShareWinner: !1,
      // 是否绑定成功
      isBindSuccess: !1,
      // 是否是下次提醒
      isNextActivityTip: !1,
      // 回调
      isNextTipCb: !1
   },
   mutations: {
      changeModuleTransitionName(state, name) {
         state.moduleTransitionName = name || 'slide';
      },
      // 通过url获取用户信息
      setUserInfo(state, obj) {
         state.userSubscribeInfo = obj;
      },
      // 获取所有活动列表
      setActivityData(state, data) {
         state.activityList = data;
      },
      // 获奖信息
      setOwnPrizeInfo(state, obj){
         state.ownPrizeInfo = obj;
      },
      // 显示城市列表
      changeCity(state, flag) {
         state.isShowCity = flag;
      },
      // 设置当前城市的id和名称
      setCurrentCityInfo(state, obj) {
         state.currentCityInfo = obj;
      },
      // 显示规则
      showRulePop(state, flag) {
         state.isShowRule = flag;
      },
      // 显示报名成功
      showSignSuccessPop(state, flag) {
         state.isSignSuccess = flag;
      },
      // 显示二维码
      showQRPop(state, flag) {
         state.isShowQR = flag;
      },
      // 显示凹凸币
      showAtbiPop(state, flag) {
         state.isShowAtbi = flag;
      },
      // 显示优惠券
      showQuanPop(state, flag) {
         state.isShowQuan = flag;
      },
      // 弹出手机绑定浮层
      showBind(state, flag) {
         state.isShowBind = flag;
      },
      // 客观别急
      showNoHurryPop(state, flag) {
         state.isShowNoHurry = flag;
      },
      // 已绑定，报名成功，已关注 弹框
      showShareSignAttentionYPop(state, flag) {
         state.isShowSignShareAttentionYes = flag;
      },
      showShareSignAttentionNPop(state, flag) {
         state.isShowSignShareAttentionNo = flag;
      },
      showShareWinnerPop(state, flag) {
         state.isShowShareWinner = flag;
      },
      // 服务时间
      serverTime(state, value){
         state.serverTime = value;
      },
      // 设置当前活动信息
      setCurrentActivityInfo(state, obj){
         state.currentActivityInfo = obj;
      },
      bindSuccess(state, value){
         state.isBindSuccess = value;
         
         if(value){
            state.userSubscribeInfo.bind = 1;
         }
      },
      // 是否新老用户
      newUser(state, value){
         state.isNew = value;
      },
      // 下期活动回调
      nextActivityTip(state, value){
         state.isNextActivityTip = value;
      },
      nextActivityTipCb(state, value){
         state.isNextTipCb = value;
      }
   },
   actions: {
      setUserInfo({
         commit
      }, obj) {
         commit('setUserInfo', obj);
      },
      setActionSignSuccessPop({
         commit
      }, flag) {
         setTimeout(() => {
            commit('showSignSuccessPop', false);
         }, 4000);
      },
      setOwnPrizeInfo({
         commit
      }, obj) {
         commit('setOwnPrizeInfo', obj);
      },
   },
   getters: {
      // 城市列表
      cityList: state => {
         let cl = [];
         for (let i = 0, _len = state.activityList.length; i < _len; i++) {
            let obj = {
               cityName: state.activityList[i].cityName,
               cityCode: state.activityList[i].cityCode,
               startTime: state.activityList[i].current? state.activityList[i].current.startTime : '',
               // sb方法 匹配城市
               fullName: state.activityList[i].cityName.length > 2? state.activityList[i].cityName: state.activityList[i].cityName + '市'
            };
            cl.push(obj);
         }
         return cl;
      }
   },
   modules: {

   }
});

export default store;